﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;

using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Routines;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.DBC;
using Styx.WoWInternals.WoWObjects;
using Styx.MemoryManagement;

namespace WuzzMonk
{
    public partial class Monk : CombatRoutine
    {
        public void WindwalkerRotation()
        {
            float EnergyPerSec = 10;

            if (!Me.CurrentTarget.IsPlayer && !Me.Auras.ContainsKey("Touch of Karma")
                    && Me.CurrentTarget.CurrentHealth <= Me.MaxHealth && Me.CurrentTarget.CurrentHealth >= (Me.MaxHealth * 0.5)
                    && Me.CurrentTarget.IsWithinMeleeRange)
                if (CastSpell("Touch of Death", Me.CurrentTarget))
                    return;

            if (Me.CurrentChi == 0 && Me.CurrentTarget.IsWithinMeleeRange)
                if (CastSpecial("Chi Brew", null))
                    return;

            // rising_sun_kick if=!target.debuff.rising_sun_kick.remains|target.debuff.rising_sun_kick.remains<=3
            if (Me.CurrentTarget.IsWithinMeleeRange)
                if (CastSpell("Rising Sun Kick", Me.CurrentTarget))
                    return;

            if ((!Helpers.Unit.HasMyAura(Me, "Tiger Power", 3) || Me.Auras["Tiger Power"].TimeLeft.Seconds < 3) && Me.CurrentTarget.IsWithinMeleeRange)
                if (CastSpell("Tiger Palm", Me.CurrentTarget))
                    return;

            if (Helpers.Unit.HasMyAura(Me, "Tigereye Brew", 10) && Me.CurrentTarget.IsWithinMeleeRange)
                if (CastBuff("Tigereye Brew", null))
                    return;

            if(Me.CurrentEnergy <= (Me.MaxEnergy - (EnergyPerSec * 5)))
                if (CastBuff("Energizing Brew", null))
                    return;

            if (Me.CurrentTarget.IsWithinMeleeRange)
                if (CastSpecial("Invoke Xuen, the White Tiger", null))
                    return;

            if (Me.CurrentTarget.IsWithinMeleeRange)
                if (CastSpell("Rushing Jade Wind", null))
                    return;

            // AoE Rotation
            if (SpellManager.HasSpell("Spinning Crane Kick") && Helpers.Unit.NearbyUnfriendlyUnits(8).Count() >= 5)
            {
                if (Me.CurrentChi == 4 && Me.CurrentTarget.IsWithinMeleeRange)
                    if (CastSpell("Rising Sun Kick", Me.CurrentTarget))
                        return;

                if (CastSpell("Spinning Crane Kick", null))
                    return;
            }

            // Single Target Rotation
            else
            {
                if (Me.CurrentTarget.IsWithinMeleeRange)
                    if (CastSpell("Rising Sun Kick", Me.CurrentTarget))
                        return;

                if (!Me.HasAura("Energizing Brew") && Me.CurrentEnergy <= Me.MaxEnergy - (EnergyPerSec * SpellManager.Spells["Fists of Fury"].MaxDuration) && Helpers.Unit.HasMyAura(Me, "Tiger Power", 3) && Me.CurrentTarget.IsWithinMeleeRange)
                    if (CastSpell("Fists of Fury", Me.CurrentTarget))
                        return;
                
                if (Me.HasAura("Combo Breaker: Blackout Kick") && Me.CurrentTarget.IsWithinMeleeRange)
                    if (CastSpell("Blackout Kick", Me.CurrentTarget))
                        return;
                
                if (Me.CurrentChi >= 3 && Me.CurrentEnergy <= Me.MaxEnergy - (EnergyPerSec * 2) && Me.CurrentTarget.IsWithinMeleeRange)
                    if (CastSpell("Blackout Kick", Me.CurrentTarget))
                        return;

                //actions.st+=/tiger_palm,if=(buff.combo_breaker_tp.react&energy.time_to_max>=2)|(buff.combo_breaker_tp.remains<=2&buff.combo_breaker_tp.up)
                if (Me.HasAura("Combo Breaker: Tiger Palm") && Me.CurrentTarget.IsWithinMeleeRange)
                    if (CastSpell("Tiger Palm", Me.CurrentTarget))
                        return;
                
                if (Me.CurrentChi <= 2 && Me.CurrentTarget.IsWithinMeleeRange)
                    if (CastSpell("Jab", Me.CurrentTarget))
                        return;

                //actions.st+=/blackout_kick,if=((energy+(energy.regen*(cooldown.rising_sun_kick.remains)))>=40)|chi=4
                if (Me.CurrentChi == 4 && Me.CurrentTarget.IsWithinMeleeRange)
                    if (CastSpell("Blackout Kick", Me.CurrentTarget))
                        return;
            }
        }

    }
}